/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.２４
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   io窗口程序
*                                                                         *
 ***************************************************************************/
#include "../CommunicateDelegate/communicatenormaldelegate.h"
#include "systemstatusdelegate.h"
#include <QDebug>
#include "../FtpManage/ftpmanage.h"
#include "hmicommondefine.h"
#include "instructionEnum.h"


extern FtpManage *ftpManage;

extern FileData fileData;

SystemStatusDelegate::SystemStatusDelegate(CommunicateNormalDelegate *communicateNormalDelegateIn,
                                           SystemStatus *systemStatusIn, GlobalData *globalDataIn,
                                  GlobalData *ioDataIn, MoveOperation *moveOperationIn,
                                           QObject* parent):QObject(parent)
{
    communicateNormalDelegate=communicateNormalDelegateIn;
    ioData = ioDataIn;
    globalPointData = globalDataIn;
    moveOperation=moveOperationIn;
    systemStatus=systemStatusIn;

    //初始化数据统一于此处
    //为了应对 当角色切换之后 所有界面都要初始化
    initDataSlot();
    initConnect();
}

void SystemStatusDelegate::initDataSlot()
{
    qDebug()<<" io init all data";
    diCount = 0;
    doCount = 0;
    siCount = 0;
    soCount = 0;
    aiCount = 0;
    aoCount = 0;
    grCount = 0;
    rCount = 0;
    prCount = 0;
    plCount = 0;
    timeCount = 0;
    gCount = 0;
    diCountFlag = true;
    doCountFlag = true;
    siCountFlag = true;
    soCountFlag = true;
    aiCountFlag = true;
    aoCountFlag = true;
    grCountFlag = true;
    rCountFlag = true;
    prCountFlag = true;
    plCountFlag = true;
    timeCountFlag = true;
    gCountFlag = true;

    grChangeFlag = true;
    rChangeFlag = true;
    prChangeFlag = true;
    plChangeFlag = true;
    timeChangeFlag = true;
    gChangeFlag = true;

    //
//    moveToPrFlag = false;
}

void SystemStatusDelegate::initConnect()
{
    //connect(systemStatus->aiStatusView,SIGNAL(aiStatusSearch()),this,SLOT(aiStatusSearchSlot()));
    connect(systemStatus->aiStatusView,SIGNAL(setNote(int ,QString )),this,SLOT(aiSetNoteSlot(int,QString)));

    //connect(systemStatus->aoStatusView,SIGNAL(aoStatusSearch()),this,SLOT(aoStatusSearchSlot()));
    connect(systemStatus->aoStatusView,SIGNAL(setAoValue(int,float)),this,SLOT(setAoValueSlot(int,float)));
    connect(systemStatus->aoStatusView,SIGNAL(setNote(int ,QString )),this,SLOT(aoSetNoteSlot(int,QString)));

    //connect(systemStatus->diStatusView,SIGNAL(diStatusSearch()),this,SLOT(diStatusSearchSlot()));
    connect(systemStatus->diStatusView,SIGNAL(setNote(int ,QString )),this,SLOT(diSetNoteSlot(int,QString)));

    //connect(systemStatus->doStatusView,SIGNAL(doStatusSearch()),this,SLOT(doStatusSearchSlot()));
    connect(systemStatus->doStatusView,SIGNAL(setDoValue(int,bool)),this,SLOT(setDoValueSlot(int,bool)));
    connect(systemStatus->doStatusView,SIGNAL(setNote(int ,QString )),this,SLOT(doSetNoteSlot(int,QString)));

    connect(systemStatus->siStatusView,SIGNAL(siStatusSearch()),this,SLOT(siStatusSearchSlot()));
    connect(systemStatus->siStatusView,SIGNAL(setNote(int ,QString )),this,SLOT(siSetNoteSlot(int,QString)));

    //connect(systemStatus->registerStatusView,SIGNAL(registerStatusSearch()),this,SLOT(registerStatusSearchSlot()));
    connect(systemStatus->registerStatusView,SIGNAL(setRegisterValue(int,float)),this,SLOT(setRegisterValueSlot(int,float)));
    connect(systemStatus->registerStatusView,SIGNAL(clearAllRegister()),this,SLOT(clearAllRegisterSlot()));

    //connect(systemStatus->soStatusView,SIGNAL(soStatusSearch()),this,SLOT(soStatusSearchSlot()));
    connect(systemStatus->soStatusView,SIGNAL(setSoValue(int,bool)),this,SLOT(setSoValueSlot(int,bool)));
    connect(systemStatus->soStatusView,SIGNAL(setNote(int ,QString )),this,SLOT(soSetNoteSlot(int,QString)));

    //connect(systemStatus->generalStatusView,SIGNAL(generalStatusSearch()),this,SLOT(generalStatusSearchSlot()));

    //connect(systemStatus->globalRegisterStatusView,SIGNAL(globalRegisterStatusSearch()),this,SLOT(globalRegisterStatusSearchSlot()));
    connect(systemStatus->globalRegisterStatusView,SIGNAL(setGlobalRegisterValue(int,float)),this,SLOT(setGlobalRegisterValueSlot(int,float)));
    connect(systemStatus->globalRegisterStatusView,SIGNAL(clearAllGlobalRegister()),this,SLOT(clearAllGlobalRegisterSlot()));

    //connect(systemStatus->palletRegisterStatusView,SIGNAL(palletRegisterStatusSearch()),this,SLOT(palletRegisterStatusSearchSlot()));
    connect(systemStatus->palletRegisterStatusView,SIGNAL(setPalletRegisterValue(int,float,float,float)),this,SLOT(setPalletRegisterValueSlot(int,float,float,float)));
    connect(systemStatus->palletRegisterStatusView,SIGNAL(clearAllPalletRegister()),this,SLOT(clearAllPalletRegisterSlot()));

    //connect(systemStatus->timerStatusView,SIGNAL(timerStatusSearch()),this,SLOT(timerStatusSearchSlot()));
    connect(systemStatus->timerStatusView,SIGNAL(beginTimer(int)),this,SLOT(beginTimerSlot(int)));
    connect(systemStatus->timerStatusView,SIGNAL(ceaseTimer(int)),this,SLOT(ceaseTimerSlot(int)));
    connect(systemStatus->timerStatusView,SIGNAL(resetTimer(int)),this,SLOT(resetTimerSlot(int)));

    connect(systemStatus->pointRegisterStatusView,SIGNAL(pointRegisterStatusFlagSignal()),this,SLOT(pointRegisterStatusFlagSlot()));
    connect(systemStatus->pointRegisterStatusView,SIGNAL(lMove(int)),this,SLOT(lMoveSlot(int)));
    connect(systemStatus->pointRegisterStatusView,SIGNAL(jMove(int)),this,SLOT(jMoveSlot(int)));
    connect(systemStatus->pointRegisterStatusView,SIGNAL(moveStop()),this,SLOT(stopMoveSlot()));
    connect(systemStatus->pointRegisterStatusView,SIGNAL(recordPoint(int)),this,SLOT(recordPointSlot(int)));
    connect(systemStatus->pointRegisterStatusView,SIGNAL(changePointTypeToJoint(int)),this,SLOT(changePointTypeToJointSlot(int)));
    connect(systemStatus->pointRegisterStatusView,SIGNAL(changePointTypeToCartesian(int)),this,SLOT(changePointTypeToCartesianSlot(int)));

    // FTP上传修改好的IOMap.xml
    connect(this, SIGNAL(ftpPutFileSignal(QString,QString)), this, SLOT(ftpPutFileSlot(QString,QString)));

}

SystemStatusDelegate::~SystemStatusDelegate()
{

}

void SystemStatusDelegate::updateViewAndData()
{
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_DI)
    {
        diStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_DO)
    {
        doStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_SI)
    {
        siStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_SO)
    {
        soStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_AI)
    {
        aiStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_AO)
    {
        aoStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_GR)
    {
        globalRegisterStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_R)
    {
        registerStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_PR)
    {
        pointRegisterStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_PL)
    {
        palletRegisterStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_TIME)
    {
        timerStatusSearchSlot();
    }
    if(systemStatus->nowSysVIewID == EM_SYS_VIEW_G)
    {
        generalStatusSearchSlot();
    }
}

void SystemStatusDelegate::ftpPutFileSlot(const QString &fileName, const QString &Path)
{
    if(globalPointData->isUseFtpOrNfs)
    {
        // 上传文件
        ftpManage->ftpPutFile(fileName, Path, Path);
    }

}

void SystemStatusDelegate::diStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<bool> ioDI,ioDo,iosi,ioso;
        std::vector<double> ioai,ioao;
        ioData->getAiAoSiSo(ioDI,ioDo,ioai,ioao,iosi,ioso);
//        if(ioData->tryLock() )
//        {
            if(diCountFlag)                             //初始化状态:容器大小
            {         
                // 获取DI数量
                diCount = ioDI.size();      // 数量为0,原因未知
                if(diCount > 0)
//                diCount = fileData.ioMsgData[IO_TYPE_DI].size();
//                if(diCount > 0)
                {
                    systemStatus->diStatusView->diValue.resize(diCount);
                    systemStatus->diStatusView->tmpDiValue.resize(diCount);
                    systemStatus->diStatusView->note.clear();
                    if(fileData.ioMsgData.size()>IO_TYPE_DI)
                    {
                        // 将DI数据更新显示到界面上
                        systemStatus->diStatusView->note = fileData.ioMsgData[IO_TYPE_DI];
                    }

                    diCountFlag = false;

                    //2017.03.31补充 当角色切换后 界面也需要重新初始化
                    systemStatus->diStatusView->initFlag = true;
                }
            }

            //qDebug()<<globalData->ioIn.size();
            if(diCount > 0 && diCount == ioDI.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
            {
                //已有初始数据,仅刷新
                for(int i = 0;i < diCount ;i++)
                {
                    if(ioDI[i])
                    {
                        systemStatus->diStatusView->diValue[i] = true;
                    }
                    else
                    {
                        systemStatus->diStatusView->diValue[i] = false;
                    }
                }
            }
            else
            {
                diCountFlag = true;
            }

//            ioData->unlock();
//        }
    }

    if(diCount > 0)//存在才更新
    {
        systemStatus->diStatusView->updateView();
    }
}

void SystemStatusDelegate::doStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<bool> ioDI,ioDo,iosi,ioso;
        std::vector<double> ioai,ioao;
        ioData->getAiAoSiSo(ioDI,ioDo,ioai,ioao,iosi,ioso);
//        if(ioData->tryLock() )
//        {
            if(doCountFlag)                             //初始化状态:容器大小
            {
                doCount = ioDo.size();
                if(doCount > 0)
                {
                    systemStatus->doStatusView->doValue.resize(doCount);
                    systemStatus->doStatusView->tmpDoValue.resize(doCount);

                    systemStatus->doStatusView->note.clear();
                    if(fileData.ioMsgData.size()>IO_TYPE_DO)
                    {
                        systemStatus->doStatusView->note = fileData.ioMsgData[IO_TYPE_DO];
                    }


                    doCountFlag = false;

                    //2017.03.31补充 当角色切换后 界面也需要重新初始化
                    systemStatus->doStatusView->initFlag = true;
                }
            }

            //qDebug()<<globalData->ioIn.size();
            if(doCount > 0 && doCount == ioDo.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
            {
                //已有初始数据,仅刷新
                for(int i = 0;i < doCount ;i++)
                {
                    if(ioDo[i])
                    {
                        systemStatus->doStatusView->doValue[i] = true;
                    }
                    else
                    {
                        systemStatus->doStatusView->doValue[i] = false;
                    }

                }
            }
            else
            {
                doCountFlag = true;
            }
//            ioData->unlock();
//        }
    }

    if(doCount > 0)//存在才更新
    {
        systemStatus->doStatusView->updateView();
    }
}

void SystemStatusDelegate::siStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<bool> ioDI,ioDo,iosi,ioso;
        std::vector<double> ioai,ioao;
        ioData->getAiAoSiSo(ioDI,ioDo,ioai,ioao,iosi,ioso);
//        if(ioData->tryLock() ){
        if(siCountFlag)                             //初始化状态:容器大小
        {
            siCount = iosi.size();
            if(siCount > 0)
            {
                systemStatus->siStatusView->siValue.resize(siCount);
                systemStatus->siStatusView->tmpSiValue.resize(siCount);

                systemStatus->siStatusView->note.clear();
                if(fileData.ioMsgData.size()>IO_TYPE_SI)
                {
                    systemStatus->siStatusView->note = fileData.ioMsgData[IO_TYPE_SI];
                }


                siCountFlag = false;

                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->siStatusView->initFlag = true;
            }
        }

        //qDebug()<<globalData->ioIn.size();
        if(siCount > 0 && siCount == iosi.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
        {
            //已有初始数据,仅刷新
            for(int i = 0;i < siCount ;i++)
            {
                if(iosi[i])
                {
                    systemStatus->siStatusView->siValue[i] = true;
                }
                else
                {
                    systemStatus->siStatusView->siValue[i] = false;
                }

            }
        }
        else
        {
            siCountFlag = true;
        }
//        ioData->unlock();}
//    }
    }

    if(siCount > 0)//存在才更新
    {
        systemStatus->siStatusView->updateView();
    }
}

void SystemStatusDelegate::soStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<bool> ioDI,ioDo,iosi,ioso;
        std::vector<double> ioai,ioao;
        ioData->getAiAoSiSo(ioDI,ioDo,ioai,ioao,iosi,ioso);
//        if(ioData->tryLock() ){

        if(soCountFlag)                             //初始化状态:容器大小
        {
            soCount = ioso.size();
            if(soCount > 0)
            {
                systemStatus->soStatusView->soValue.resize(soCount);
                systemStatus->soStatusView->tmpSoValue.resize(soCount);

                systemStatus->soStatusView->note.clear();
                if(fileData.ioMsgData.size()>IO_TYPE_SO)
                {
                    systemStatus->soStatusView->note = fileData.ioMsgData[IO_TYPE_SO];
                }


                soCountFlag = false;


                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->soStatusView->initFlag = true;
            }
        }

        //qDebug()<<globalData->ioIn.size();
        if(soCount > 0 && soCount == ioso.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
        {
            //已有初始数据,仅刷新
            for(int i = 0;i < soCount ;i++)
            {
                if(ioso[i])
                {
                    systemStatus->soStatusView->soValue[i] = true;
                }
                else
                {
                    systemStatus->soStatusView->soValue[i] = false;
                }

            }
        }
        else
        {
            soCountFlag = false;
        }
//        ioData->unlock();}
//    }
    }

    if(soCount > 0)//存在才更新
    {
        systemStatus->soStatusView->updateView();
    }
}

void SystemStatusDelegate::aiStatusSearchSlot()
{
    if(ioData)
    {
//        if(ioData->tryLock() ){
        std::vector<bool> ioDI,ioDo,iosi,ioso;
        std::vector<double> ioai,ioao;
        ioData->getAiAoSiSo(ioDI,ioDo,ioai,ioao,iosi,ioso);
        if(aiCountFlag)                             //初始化状态:容器大小
        {
            aiCount = ioai.size();
            if(aiCount > 0)
            {
                systemStatus->aiStatusView->aiValue.resize(aiCount);

                systemStatus->aiStatusView->note.clear();
                if(fileData.ioMsgData.size()>IO_TYPE_AI)
                {
                    systemStatus->aiStatusView->note = fileData.ioMsgData[IO_TYPE_AI];
                }


                aiCountFlag = false;

                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->aiStatusView->initFlag = true;
            }
        }

        //qDebug()<<globalData->ioIn.size();
        if(aiCount > 0 && aiCount == ioai.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
        {
            //已有初始数据,仅刷新
            for(int i = 0;i < aiCount ;i++)
            {
                systemStatus->aiStatusView->aiValue[i] = ioai[i];
            }
        }
        else
        {
            aiCountFlag = true;
        }
//        ioData->unlock();}
    }

    if(aiCount > 0)//存在才更新
    {
        systemStatus->aiStatusView->updateView();
    }
}

void SystemStatusDelegate::aoStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<bool> ioDI,ioDo,iosi,ioso;
        std::vector<double> ioai,ioao;
        ioData->getAiAoSiSo(ioDI,ioDo,ioai,ioao,iosi,ioso);
//        if(ioData->tryLock() ){

        if(aoCountFlag)                             //初始化状态:容器大小
        {
            aoCount = ioao.size();
            if(aoCount > 0)
            {
                systemStatus->aoStatusView->aoValue.resize(aoCount);

                systemStatus->aoStatusView->note.clear();
                if(fileData.ioMsgData.size()>IO_TYPE_AO)
                {
                    systemStatus->aoStatusView->note = fileData.ioMsgData[IO_TYPE_AO];
                }


                aoCountFlag = false;

                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->aoStatusView->initFlag = true;
            }
        }

        //qDebug()<<globalData->ioIn.size();
        if(aoCount > 0 && aoCount == ioao.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
        {
            //已有初始数据,仅刷新
            for(int i = 0;i < aoCount ;i++)
            {
                systemStatus->aoStatusView->aoValue[i] = ioao[i];
            }
        }
        else
        {
            aoCountFlag = true;
        }
//        ioData->unlock();}
    }

    if(aoCount > 0)//存在才更新
    {
        systemStatus->aoStatusView->updateView();
    }
}



void SystemStatusDelegate::generalStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<CommRobotInfo> robotInfoListLv3Out;
        ioData->getRobotInfoListLv3(robotInfoListLv3Out);
        ControllerTimeHistory timeHistoryOut;
        ioData->getControllerTimeHistroy(timeHistoryOut);
//        if(ioData->tryLock())
//        {
            //qDebug()<<QString::fromStdString(globalData->powerOnTime);
            systemStatus->generalStatusView->powerOnTime = QString::fromStdString(timeHistoryOut.powerOnTime);
            systemStatus->generalStatusView->totalPowerOnTime = QString::fromStdString(timeHistoryOut.totalPowerOnTime);
            systemStatus->generalStatusView->totalStartOnTime = QString::fromStdString(timeHistoryOut.totalStartOnTime);
            systemStatus->generalStatusView->servoOnTime = QString::fromStdString(timeHistoryOut.servoOnTime);

            //
            if(gCountFlag)                             //初始化状态:容器大小
            {
                gCount = robotInfoListLv3Out.size();
                if(gCount > 0)
                {
                    systemStatus->generalStatusView->robotId.resize(gCount);
                    systemStatus->generalStatusView->robotName.resize(gCount);
                    systemStatus->generalStatusView->robotStatus.resize(gCount);
                    systemStatus->generalStatusView->robotProgram.resize(gCount);
                    systemStatus->generalStatusView->robotSpeed.resize(gCount);

                    gCountFlag = false;

                    //2017.03.31补充 当角色切换后 界面也需要重新初始化
                    systemStatus->generalStatusView->initFlag = true;
                }
            }

            if(gChangeFlag)
            {
                if(gCount > 0 && gCount == robotInfoListLv3Out.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
                {
                    //已有初始数据,仅刷新
                    for(int i = 0;i < gCount ;i++)
                    {
                        systemStatus->generalStatusView->robotId[i] = robotInfoListLv3Out[i].robotId;
                        systemStatus->generalStatusView->robotName[i] =
                                QString::fromStdString(robotInfoListLv3Out[i].robotName);
                        systemStatus->generalStatusView->robotStatus[i] = robotInfoListLv3Out[i].robotStatus;
                        systemStatus->generalStatusView->robotProgram[i] = QString::fromStdString(robotInfoListLv3Out[i].robotProgram);
                        systemStatus->generalStatusView->robotSpeed[i] = robotInfoListLv3Out[i].robotRunSpeed;
                    }
                }
            }

//            ioData->unlock();
//        }
    }

    //if(gCount > 0)//存在才更新
    {
        systemStatus->generalStatusView->updateView();
        gChangeFlag = true;//如果需要更新内容,外部设置重启true便可
    }

}

void SystemStatusDelegate::timerStatusSearchSlot()
{
    if(ioData)
    {
//        if(ioData->tryLock() ){
        std::vector<double > registerOut;
        ioData->getTimerRegister(registerOut);
        if(timeCountFlag)                             //初始化状态:容器大小
        {
            timeCount = registerOut.size();
            if(timeCount > 0)
            {
                systemStatus->timerStatusView->timerValue.resize(timeCount);
                timeCountFlag = false;

                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->timerStatusView->initFlag = true;
            }
        }

        //qDebug()<<globalData->ioIn.size();
        if(timeChangeFlag)
        {
            if(timeCount > 0 && timeCount == registerOut.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
            {
                //已有初始数据,仅刷新
                for(int i = 0;i < timeCount ;i++)
                {
                    systemStatus->timerStatusView->timerValue[i] = registerOut[i];
                }
            }
        }
//        ioData->unlock();}
    }

    if(timeCount > 0)//存在才更新
    {
        systemStatus->timerStatusView->updateView();
        //timeChangeFlag = false;//如果需要更新内容,外部设置重启true便可
    }
}

void SystemStatusDelegate::registerStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<double > registerOut;
        ioData->getLocalRegister(registerOut);
//        if(ioData->tryLock() ){

            if(rCountFlag)                             //初始化状态:容器大小
            {
                rCount = registerOut.size();
                if(rCount > 0)
                {
                    systemStatus->registerStatusView->registerValue.resize(rCount);
                    rCountFlag = false;

                    //2017.03.31补充 当角色切换后 界面也需要重新初始化
                    systemStatus->registerStatusView->initFlag = true;
                }
            }

            if(rChangeFlag)
            {
                if(rCount > 0 && rCount == registerOut.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
                {
                    //已有初始数据,仅刷新
                    for(int i = 0;i < rCount ;i++)
                    {
                        systemStatus->registerStatusView->registerValue[i] = registerOut[i];
                    }
                }
            }
//            ioData->unlock();
//        }
    }

    if(rCount > 0)//存在才更新
    {
        systemStatus->registerStatusView->updateView();
        //rChangeFlag = false;//如果需要更新内容,外部设置重启true便可
    }
}

void SystemStatusDelegate::globalRegisterStatusSearchSlot()
{

    if(ioData)
    {
        std::vector<double > registerOut;
        ioData->getGlobalRegister(registerOut);
//        if(ioData->tryLock() ){

        if(grCountFlag)                             //初始化状态:容器大小
        {
            grCount = registerOut.size();
            if(grCount > 0)
            {
                systemStatus->globalRegisterStatusView->globalRegisterValue.resize(grCount);
                grCountFlag = false;

                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->globalRegisterStatusView->initFlag = true;
            }
        }

        if(grChangeFlag)
        {
            if(grCount > 0 && grCount == registerOut.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
            {
                //已有初始数据,仅刷新
                for(int i = 0;i < grCount ;i++)
                {
                    systemStatus->globalRegisterStatusView->globalRegisterValue[i] = registerOut[i];
                }
            }
        }
//        ioData->unlock();}
    }

    if(grCount > 0)//存在才更新
    {
        systemStatus->globalRegisterStatusView->updateView();
        //grChangeFlag = false;//如果需要更新内容,外部设置重启true便可
    }
}

void SystemStatusDelegate::palletRegisterStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<PlRegStruct> registerOut;
        ioData->getPlRegister(registerOut);
//        if(ioData->tryLock() ){

        if(plCountFlag)                             //初始化状态:容器大小
        {
            plCount = registerOut.size();
            if(plCount > 0)
            {
                systemStatus->palletRegisterStatusView->row.resize(plCount);
                systemStatus->palletRegisterStatusView->column.resize(plCount);
                systemStatus->palletRegisterStatusView->floor.resize(plCount);
                plCountFlag = false;

                //2017.03.31补充 当角色切换后 界面也需要重新初始化
                systemStatus->palletRegisterStatusView->initFlag = true;
            }
        }

        if(plChangeFlag)
        {
            if(plCount > 0 && plCount == registerOut.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
            {
                //已有初始数据,仅刷新
                for(int i = 0;i < plCount ;i++)
                {
                    systemStatus->palletRegisterStatusView->row[i] = registerOut[i].row;
                    systemStatus->palletRegisterStatusView->column[i] = registerOut[i].col;
                    systemStatus->palletRegisterStatusView->floor[i] = registerOut[i].layer;
                }
            }
        }
//        ioData->unlock();}
    }

    if(plCount > 0)//存在才更新
    {
        systemStatus->palletRegisterStatusView->updateView();
        //plChangeFlag = false;//如果需要更新内容,外部设置重启true便可
    }
}

void SystemStatusDelegate::pointRegisterStatusFlagSlot()
{
    prChangeFlag = true;
}

void SystemStatusDelegate::pointRegisterStatusSearchSlot()
{
    if(ioData)
    {
        std::vector<PointPro> registerOut;
        ioData->getPointRegister(registerOut);
//        if(ioData->tryLock() )
//        {
            if(prCountFlag)                             //初始化状态:容器大小
            {
                prCount = registerOut.size();
                if(prCount > 0)
                {
                    systemStatus->pointRegisterStatusView->pointList.resize(prCount);
                    prCountFlag = false;

                    //2017.03.31补充 当角色切换后 界面也需要重新初始化
                    systemStatus->pointRegisterStatusView->initFlag = true;
                }
            }

            if(prChangeFlag)
            {
                if(prCount > 0 && prCount == registerOut.size())//已经初始化 而且数量没变化(数量不一致就不更新,应该提示重启系统)
                {
                    //已有初始数据,仅刷新
                    for(int i = 0;i < prCount ;i++)
                    {
//                        systemStatus->pointRegisterStatusView->pointList[i].jointFlag = globalData->pointRegister[i].jointFlag;
//                        systemStatus->pointRegisterStatusView->pointList[i].pointNum = globalData->pointRegister[i].pointNum;
//                        systemStatus->pointRegisterStatusView->pointList[i].groupNum = globalData->pointRegister[i].groupNum;
//                        systemStatus->pointRegisterStatusView->pointList[i].ufValue = globalData->pointRegister[i].ufValue;
//                        systemStatus->pointRegisterStatusView->pointList[i].utValue = globalData->pointRegister[i].utValue;
//                        systemStatus->pointRegisterStatusView->pointList[i].recordStatus = globalData->pointRegister[i].recordStatus;
//                        systemStatus->pointRegisterStatusView->pointList[i].configString = globalData->pointRegister[i].configString;

//                        systemStatus->pointRegisterStatusView->pointList[i].configInt.swap(globalData->pointRegister[i].configInt);
//                        systemStatus->pointRegisterStatusView->pointList[i].positionValue.swap(globalData->pointRegister[i].positionValue);
//                        systemStatus->pointRegisterStatusView->pointList[i].extPositionValue.swap(globalData->pointRegister[i].extPositionValue);
                        systemStatus->pointRegisterStatusView->pointList[i] = registerOut[i];
                    }
                }
            }
//            ioData->unlock();
//        }
    }

    //qDebug()<<systemStatus->pointRegisterStatusView->pointList.size();

    if(prCount > 0)//存在才更新
    {

        systemStatus->pointRegisterStatusView->updateView();
        //prChangeFlag = false;//如果需要更新内容,外部设置重启true便可
    }
}

void SystemStatusDelegate::setRegisterValueSlot(int index,float value)
{
    //qDebug()<<"rvalue";
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<index<<value;
            emit setRSignal(index, value);
        }
//        globalPointData->unlock();
//    }

    //rChangeFlag = true;//开启更新标志位
}

void SystemStatusDelegate::clearAllRegisterSlot()
{
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            qDebug()<<"clearall";
            emit setRClearSignal();
        }
//        globalPointData->unlock();
//    }

    //rChangeFlag = true;//开启更新标志位
}

void SystemStatusDelegate::setGlobalRegisterValueSlot(int index,float value)
{
    //qDebug()<<"grvalue";

//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<index<<value;
            emit setGrSignal(index , value);
        }

//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::clearAllGlobalRegisterSlot()
{
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            qDebug()<<"clearall";
            emit setGrClearSignal();
        }

//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::setPalletRegisterValueSlot(int index, float row, float col, float layer)
{
    //qDebug()<<"prvalue";
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<index<<row<<col<<layer;
            emit setPlSignal(index , row , col , layer);
        }
//        globalPointData->unlock();
//    }

    //plChangeFlag = true;//开启 更新标志位
}

void SystemStatusDelegate::clearAllPalletRegisterSlot()
{
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN || globalPointData->globalCurrentState == ENUM_COMMAND_CEASE)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            qDebug()<<"clearall";
            emit setPlClearSignal();
        }
//        globalPointData->unlock();
//    }

    //plChangeFlag = true;//开启 更新标志位
}

void SystemStatusDelegate::beginTimerSlot(int index)
{
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN || globalPointData->globalCurrentState == ENUM_COMMAND_CEASE)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<"begin";
            //qDebug()<<index;
            emit setTimeSignal(index,EM_TIME_START);
        }
//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::ceaseTimerSlot(int index)
{
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN || globalPointData->globalCurrentState == ENUM_COMMAND_CEASE)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<"cease";
            //qDebug()<<index;
            emit setTimeSignal(index,EM_TIME_STOP);
        }
//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::resetTimerSlot(int index)
{
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN || globalPointData->globalCurrentState == ENUM_COMMAND_CEASE)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<"reset";
            //qDebug()<<index;
            emit setTimeSignal(index,EM_TIME_RESET);
        }
//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::jMoveSlot(int index)
{
    qDebug()<<"jMoveSlot";
    moveToPoint(0,index);
}

void SystemStatusDelegate::lMoveSlot(int index)
{
    qDebug()<<"lMoveSlot";
    moveToPoint(1,index);
}

void SystemStatusDelegate::moveToPoint(int moveType , int pointIndex)
{
//    if(globalPointData)
//    {
//        if(globalPointData->tryLock(TRYLOCKTIME))
//        {
//            if(globalPointData->globalHandState >= EM_CONTROL_MODE_T2)
//            {
//                globalPointData->unlock();

//                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前模式不可操作\n寸动请切换手动T1模式"));

//                return;
//            }
//            if(globalPointData->globalServoState != EM_MOTOR_STATUS_SERVO_ON)//使能开启
//            {
//                globalPointData->unlock();
//                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("伺服使能没有启动,请启动"));
//                return;
//            }
//            else
//            {
//                globalPointData->unlock();
//            }
//        }
//    }

    //新尝试,直接赋值过去
    MoveParameter tmpPoint;
    tmpPoint.moveType = moveType;
    tmpPoint.pointType = 2;//0 普通P点 1 码垛 2　PR寄存器点
    tmpPoint.targetPoint = systemStatus->pointRegisterStatusView->pointList[pointIndex];
    //2017-04-13 (不需要补充,已有)补充判断:有无点数据
    if(tmpPoint.targetPoint.positionValue.size() <= 0)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("该PR点没有载入点数据,请载入"));
        return;
    }

//    moveToPrFlag = true;

//    emit movePrSignal(tmpPoint);//MoveParameter point
    moveOperation->startPointMove(tmpPoint);
}

void SystemStatusDelegate::stopMoveSlot()
{
//    if(moveToPrFlag)
//    {
//        qDebug()<<"stop";//要设置标志位
//        emit stopMovePrSignal();

//        moveToPrFlag = false;
//    }

    moveOperation->stopPointMove();
}

void SystemStatusDelegate::recordPointSlot(int index)
{
    qDebug()<<"SystemStatusDelegate::recordPointSlot 机器人点";
    if(globalPointData)
    {
        PointPro currentPositionJointOut;
        globalPointData->getCurrentArmPosition_joint(currentPositionJointOut);
        PointPro currentPositionDecartOut;
        globalPointData->getCurrentArmPosition_decart(currentPositionDecartOut);
//        if(globalPointData->tryLock(TRYLOCKTIME))
//        {
            if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
            {
//                globalPointData->unlock();
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
                return;
            }

            if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
            {
//                globalPointData->unlock();
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
            }
            else
            {
                PointPro tmpPoint;
                if(globalPointData->globalCoordinate == EM_JOG_COORDINATE_JOINT)
                {
                    tmpPoint.jointFlag = EM_CF_DEG_TYPE;
                    tmpPoint.pointNum = index+1;
                    tmpPoint.groupNum = 0;//?
                    tmpPoint.ufValue = globalPointData->globalDefaultUserNum;
                    tmpPoint.utValue = globalPointData->globalDefaultToolNum;
                    tmpPoint.recordStatus = 0;
                    //多圈 目前空
                    tmpPoint.configString = "";
                    for(int i = 0;i < currentPositionJointOut.positionValue.size();i++)
                    {
                        tmpPoint.positionValue.push_back(currentPositionJointOut.positionValue[i]);//float
                        tmpPoint.positionValue[i] = QString::number(tmpPoint.positionValue[i],'f',3).toFloat();
                    }
                    for(int i = 0;i < currentPositionJointOut.extPositionValue.size();i++)
                    {
                        tmpPoint.extPositionValue.push_back(currentPositionJointOut.extPositionValue[i]);//float
                        tmpPoint.extPositionValue[i] = QString::number(tmpPoint.extPositionValue[i],'f',3).toFloat();
                    }
                }
                else
                {
                    tmpPoint.jointFlag = EM_CF_WORLD_TYPE;//globalPointData->globalCoordinate;
                    tmpPoint.pointNum = index+1;
                    tmpPoint.groupNum = 0;
                    tmpPoint.ufValue = globalPointData->globalDefaultUserNum;
                    tmpPoint.utValue = globalPointData->globalDefaultToolNum;
                    tmpPoint.recordStatus = 0;
                    //多圈 目前空
                    tmpPoint.configString = currentPositionDecartOut.configString;
                    tmpPoint.configInt = currentPositionDecartOut.configInt;
                    for(int i = 0;i < currentPositionDecartOut.positionValue.size();i++)
                    {
                        tmpPoint.positionValue.push_back(currentPositionDecartOut.positionValue[i]);//float
                        tmpPoint.positionValue[i] = QString::number(tmpPoint.positionValue[i],'f',3).toFloat();
                    }
                    for(int i = 0;i < currentPositionJointOut.extPositionValue.size();i++)
                    {
                        tmpPoint.extPositionValue.push_back(currentPositionJointOut.extPositionValue[i]);//float
                        tmpPoint.extPositionValue[i] = QString::number(tmpPoint.extPositionValue[i],'f',3).toFloat();
                    }
                }
//                globalPointData->unlock();

                systemStatus->pointRegisterStatusView->pointList.replace(index,tmpPoint);

                qDebug()<<"recordpoint "<< systemStatus->pointRegisterStatusView->pointList[index].pointNum;

                //emit comm
                emit setPrSignal(index,tmpPoint);//数组下标 和 点数据pointNum = index+1;

                //update view
                //调用
                systemStatus->pointRegisterStatusView->setCurrentRowToShow(index);//行号
            }
//        }
    }
}

void SystemStatusDelegate::changePointTypeToJointSlot(int index)
{
    //2017-04-13 补充判断:有无点数据
    if(systemStatus->pointRegisterStatusView->pointList[index].positionValue.size()<=0)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据\n转换点前请先载入点"));
        return;
    }

    if(EM_CF_WORLD_TYPE == systemStatus->pointRegisterStatusView->pointList[index].jointFlag)
    {
//        if(globalPointData->tryLock(TRYLOCKTIME))
//        {
            if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
            {
//                globalPointData->unlock();
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
                return;
            }

            if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
            {
//                globalPointData->unlock();
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
                return;
            }
            else
            {
                qDebug()<<"change to deg "<<index;
                emit changePrPoint(index,systemStatus->pointRegisterStatusView->pointList[index]);
            }
//            globalPointData->unlock();
//        }
    }
}

void SystemStatusDelegate::changePointTypeToCartesianSlot(int index)
{
    //2017-04-13 补充判断:有无点数据
    if(systemStatus->pointRegisterStatusView->pointList[index].positionValue.size()<=0)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据\n转换点前请先载入点"));
        return;
    }

    if(EM_CF_DEG_TYPE == systemStatus->pointRegisterStatusView->pointList[index].jointFlag)
    {
//        if(globalPointData->tryLock(TRYLOCKTIME))
//        {
            if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
            {
//                globalPointData->unlock();
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
                return;
            }

            if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
            {
//                globalPointData->unlock();
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
                return;
            }
            else
            {
                qDebug()<<"change to world "<<index;
                emit changePrPoint(index,systemStatus->pointRegisterStatusView->pointList[index]);
            }
//            globalPointData->unlock();
//        }
    }
}

void SystemStatusDelegate::recvPrPointResultSlot(int index ,PointPro recvPoint)
{
    qDebug()<<"recvPrPointResultSlot: "<< systemStatus->pointRegisterStatusView->pointList[index].pointNum;
    systemStatus->pointRegisterStatusView->pointList.replace(index,recvPoint);

    //emit comm
    emit setPrSignal(index,recvPoint);//数组下标 和 点数据pointNum = index+1;

    //update view
    //调用
    systemStatus->pointRegisterStatusView->setCurrentRowToShow(index);//行号

}

void SystemStatusDelegate::aiSetNoteSlot(int index, QString text)
{
    //qDebug()<<"ainote";
    fileData.xmlParse.openXml(fileData.currentRobotFileAddress+"config/iomap.xml");
    fileData.xmlParse.updateIoMap(IO_TYPE_AI,index+1,text);//因为文件从1开始了
    fileData.xmlParse.closeXml();

    if(globalPointData->isUseFtpOrNfs)
    {
        QString filePath = fileData.currentRobotFileAddress+"config/";
        emit ftpPutFileSignal("iomap.xml",filePath);
    }
}

void SystemStatusDelegate::aoSetNoteSlot(int index,QString text)
{
    if(GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        // 设置AO注释名
        int returnFlag;
        communicateNormalDelegate->set_Control_AO_NameInfo(ioData->currentRobotID, index, text.toStdString(), returnFlag);
    }
    else
    {
        //qDebug()<<"aonote";
        fileData.xmlParse.openXml(fileData.currentRobotFileAddress+"config/iomap.xml");
        fileData.xmlParse.updateIoMap(IO_TYPE_AO,index+1,text);//因为文件从1开始了
        fileData.xmlParse.closeXml();

        if(globalPointData->isUseFtpOrNfs)
        {
            QString filePath = fileData.currentRobotFileAddress+"config/";
            emit ftpPutFileSignal("iomap.xml",filePath);
        }

    }
}

void SystemStatusDelegate::diSetNoteSlot(int index,QString text)
{
    // GSOAP设置DI注释名
    if(GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        int returnFlag;
        communicateNormalDelegate->set_Control_DI_NameInfo(ioData->currentRobotID, index, text.toStdString(), returnFlag);
        if(returnFlag == SOAP_OK)
        {
            qDebug() << "SystemStatusDelegate::diSetNoteSlot == true!";
        }
        else
        {
            qDebug() << "SystemStatusDelegate::diSetNoteSlot == false!";
            return;
        }
    }
    else
    {
        //qDebug()<<"dinote";
        fileData.xmlParse.openXml(fileData.currentRobotFileAddress+"config/iomap.xml");
        fileData.xmlParse.updateIoMap(IO_TYPE_DI,index+1,text);//因为文件从1开始了
        fileData.xmlParse.closeXml();

        if(globalPointData->isUseFtpOrNfs)
        {
            QString filePath = fileData.currentRobotFileAddress+"config/";
            emit ftpPutFileSignal("iomap.xml",filePath);
        }
    }
}

void SystemStatusDelegate::doSetNoteSlot(int index,QString text)
{
    if(GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        int returnFlag;
        communicateNormalDelegate->set_Control_DO_NameInfo(ioData->currentRobotID, index, text.toStdString(), returnFlag);
        if(returnFlag == SOAP_OK)
        {
            qDebug() << "SystemStatusDelegate::doSetNoteSlot == true!";
        }
        else
        {
            qDebug() << "SystemStatusDelegate::doSetNoteSlot == false!";
            return;
        }
    }
    else
    {
        //qDebug()<<"donote";
        fileData.xmlParse.openXml(fileData.currentRobotFileAddress+"config/iomap.xml");
        fileData.xmlParse.updateIoMap(IO_TYPE_DO,index+1,text);//因为文件从1开始了
        fileData.xmlParse.closeXml();

        if(globalPointData->isUseFtpOrNfs)
        {
            QString filePath = fileData.currentRobotFileAddress+"config/";
            emit ftpPutFileSignal("iomap.xml",filePath);
        }
    }
}

void SystemStatusDelegate::siSetNoteSlot(int index,QString text)
{
    if(GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        int returnFlag;
        communicateNormalDelegate->set_Control_SI_NameInfo(ioData->currentRobotID, index, text.toStdString(), returnFlag);
        if(returnFlag == SOAP_OK)
        {
            qDebug() << "SystemStatusDelegate::siSetNoteSlot == true!";
        }
        else
        {
            qDebug() << "SystemStatusDelegate::siSetNoteSlot == false!";
            return;
        }
    }
    else
    {
        //qDebug()<<"sinote";
        fileData.xmlParse.openXml(fileData.currentRobotFileAddress+"config/iomap.xml");
        fileData.xmlParse.updateIoMap(IO_TYPE_SI,index+1,text);//因为文件从1开始了
        fileData.xmlParse.closeXml();

        if(globalPointData->isUseFtpOrNfs)
        {
            QString filePath = fileData.currentRobotFileAddress+"config/";
            emit ftpPutFileSignal("iomap.xml",filePath);
        }
    }
}

void SystemStatusDelegate::soSetNoteSlot(int index,QString text)
{
    if(GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        int returnFlag;
        communicateNormalDelegate->set_Control_SO_NameInfo(ioData->currentRobotID, index, text.toStdString(), returnFlag);
        if(returnFlag == SOAP_OK)
        {
            qDebug() << "SystemStatusDelegate::soSetNoteSlot == true!";
        }
        else
        {
            qDebug() << "SystemStatusDelegate::soSetNoteSlot == false!";
            return;
        }
    }
    else
    {
        //qDebug()<<"sonote";
        fileData.xmlParse.openXml(fileData.currentRobotFileAddress+"config/iomap.xml");
        fileData.xmlParse.updateIoMap(IO_TYPE_SO,index+1,text);//因为文件从1开始了
        fileData.xmlParse.closeXml();

        if(globalPointData->isUseFtpOrNfs)
        {
            QString filePath = fileData.currentRobotFileAddress+"config/";
            emit ftpPutFileSignal("iomap.xml",filePath);
        }
    }


}

void SystemStatusDelegate::setDoValueSlot(int index,bool value)
{
    //qDebug()<<"dovalue";

//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<index<<value;
            emit setDoSignal(index ,value);
        }

//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::setAoValueSlot(int index,float aoValue)
{
    //qDebug()<<"aovalue";
//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN)
        {
            //globalPointData->unlock();

            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<index<<aoValue;
            emit setAoSignal(index ,aoValue);
        }

//        globalPointData->unlock();
//    }

}

void SystemStatusDelegate::setSoValueSlot(int index,bool value)
{
    //qDebug()<<"sovalue";

//    if(globalPointData->tryLock(TRYLOCKTIME))
//    {
        if(globalPointData->globalHandState == EM_CONTROL_MODE_AUTO)
        {
//            globalPointData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前处于自动模式\n禁止操作"));
            return;
        }

        if(globalPointData->globalCurrentState == ENUM_COMMAND_RUN )
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("程序处于非停止运行状态\n禁止操作"));
        }
        else
        {
            //qDebug()<<index<<value;
            emit setSoSignal(index ,value);
        }

//        globalPointData->unlock();
//    }
}

void SystemStatusDelegate::changeLanguageSlot(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/systemStatusDelEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    systemStatus->changeLanguage(language);
}
